package Main;

import java.io.IOException;
import Gui.GameFrame;
import GameFiles.GameManager;
import EventManager.EventManager;

public class PayDayMain implements Runnable
{
	public void run()
	{
		/**
		 * Initialization
		 */
		try
		{
			GameManager.getInstance().InitializeGame();
		} catch (IOException e1)
		{
			e1.printStackTrace();
		}
		/**
		 * Game Loop
		 */
		long soon = 0;
		long now = System.currentTimeMillis();
		while (true)
		{
			now = System.currentTimeMillis();
			if (now >= soon)
			{
				// Throttle
				soon = now + 10;
				// Draw (Also handles mouse input though ActionListener)
				GameFrame.getInstance().update();
				GameFrame.getInstance().repaint();
				GameFrame.getInstance().revalidate();
				
				//Runs for 5ms
				EventManager.getInstance().processEvents();				
				// Updates Game Logic
				GameManager.getInstance().getCurrentGameState().Execute();

			} else
			{
				try
				{
					Thread.sleep(1);
				} catch (Exception e)
				{
				}
			}
		}
		
	}
}
